home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 255_01 / gpflood.asm < prev    next >
Encoding:
Assembly Source File  |  1988-03-28  |  18.1 KB  |  652 lines

  1.           page   80,132
  2.           page
  3. ;
  4. ;         Kent Cedola
  5. ;         2015 Meadow Lake Court
  6. ;         Norfolk, Virginia  23518
  7. ;
  8.  
  9. color     equ    4
  10.  
  11. tmpw1     equ    -2
  12. tmpw2     equ    -4
  13. tmpw3     equ    -6
  14. tmpw4     equ    -8
  15. tmpw5     equ    -10
  16. tmpw6     equ    -12
  17. tmpw7     equ    -14
  18. tmpw8     equ    -16
  19. tmpw9     equ    -18
  20. tmpwA     equ    -20
  21.  
  22. needed    equ    22
  23.  
  24. dgroup    group  _data
  25.  
  26. _data     segment word public 'data'
  27.           assume ds:dgroup
  28.  
  29.           extrn  _gdtype:byte
  30.           extrn  _gdmaxcol:word,_gdmaxrow:word
  31.           extrn  _gdcolor:byte,_gdmerge:byte,_gdaspc1:word,_gdaspc2:word
  32.           extrn  _gdcur_x:word,_gdcur_y:word
  33.           extrn  _gdwd_x1:word,_gdwd_x2:word,_gdwd_x3:word
  34.           extrn  _gdwd_y1:word,_gdwd_y2:word,_gdwd_y3:word
  35.           extrn  _gdvw_x1:word,_gdvw_x2:word,_gdvw_x3:word
  36.           extrn  _gdvw_y1:word,_gdvw_y2:word,_gdvw_y3:word
  37.           extrn  _gdgsadr:word,_gdshad1:byte
  38.           extrn  _gdc_flg:byte,_gds_flg:byte,_gdw_flg:byte
  39.  
  40. _data     ends
  41.  
  42. _text     segment byte public 'code'
  43.  
  44.           assume cs:_text,ds:dgroup
  45.           public _gpflood
  46. _gpflood  proc   near
  47.  
  48.           push   bp                    ; Save caller's base frame pointer
  49.           mov    bp,sp                 ; Setup of new frame with parameters
  50.           sub    sp,needed             ; Get some room for our variables
  51.  
  52.           push   si
  53.           push   di
  54.  
  55.           mov    cx,_GDCUR_X           ; Load X corrdinate
  56.           mov    bx,_GDCUR_Y           ; Load Y corrdinate
  57.  
  58. ;      If the starting coordinate is not in the current viewport then return
  59. ;  boundry error (GDC_FLG = 2).
  60.  
  61.           CMP    CX,_GDVW_X1           ; Is the pixel below our minimum?
  62.           JL     nopoint               ;   Yes, return with a error
  63.           CMP    CX,_GDVW_X2           ; Is the pixel above our maximum?
  64.           JG     nopoint               ;   Yes, return with a error
  65.           CMP    BX,_GDVW_Y1           ; Is the pixel below our minimum?
  66.           JL     nopoint               ;   Yes, return with a error
  67.           CMP    BX,_GDVW_Y2           ; Is the pixel above our maximum?
  68.           JLE    egainit               ;   Yes, return with a error
  69. nopoint:
  70.           mov    _GDC_FLG,2            ;
  71.           jmp    done
  72.  
  73. egainit:
  74.           mov    ax,0A000h
  75.           mov    es,ax
  76.  
  77.           mov    dx,03CEh
  78.           mov    al,02
  79.           mov    ah,[BP+color]         ; Color
  80.           out    dx,ax
  81.           mov    al,3
  82.           mov    ah,_GDMERGE
  83.           out    dx,ax
  84.           mov    ax,0A05h
  85.           out    dx,ax
  86.           mov    al,08
  87.           out    dx,al
  88.           inc    dx
  89.  
  90.           XOR    AX,AX
  91.           PUSH   AX
  92.           PUSH   CX
  93.           PUSH   CX
  94.           PUSH   BX
  95.           MOV    AH,1
  96.           PUSH   AX
  97.  
  98. ;      Fill in each specified horizontal line using the current shading and
  99. ;  color values.  Then scan the rows above and below the row just filled in.
  100. ;
  101. ;         SP +0  option bits
  102. ;         SP +2  vertical bit corrdinate (Y)
  103. ;         SP +4  horizontal bit corrdinate (X)
  104. ;         SP +6  horizontal bit corrdinate (X')
  105.  
  106. loop:
  107.           mov    si,bp                 ; Save BP in holding register
  108. scan:
  109.  
  110. ;         MOV    AH,8
  111. ;         INT    21h
  112. ;         CMP    AL,'*'
  113. ;         JNE    bug1
  114. ;         INC    color
  115. ;ug1:
  116. ;         CMP    AL,'$'
  117. ;         JNE    debug
  118. ;         MOV    AX,3
  119. ;         INT    10h
  120. ;         NOP
  121. ;ebug:
  122.           MOV    BX,SP
  123.           CMP    Word Ptr ss:[BX+0],0
  124.           JNE    scan01
  125.           POP    AX
  126.           mov    bp,si
  127.           jmp    done
  128. scan01:
  129.           MOV    BP,BX
  130. scan02:
  131.           ADD    BP,8
  132.           MOV    AX,[BP+0]
  133.           OR     AX,AX
  134.           JNZ    scan02A
  135.           JMP    scan09
  136. scan02A:
  137.           MOV    AX,[BP+2]
  138.           CMP    AX,ss:[BX+2]
  139.           JNE    scan02
  140.           MOV    AX,[BP+4]
  141.           CMP    AX,ss:[BX+6]
  142.           JG     scan02
  143.           MOV    AX,[BP+6]
  144.           CMP    AX,ss:[BX+4]
  145.           JL     scan02
  146.  
  147.           XOR    CL,CL
  148.           MOV    AX,ss:[BX+4]
  149.           CMP    AX,[BP+4]
  150.           JL     scan03
  151.           OR     CL,008h
  152.           CMP    AX,[BP+4]
  153.           JNE    scan03
  154.           XOR    CL,00Ch
  155. scan03:
  156.           MOV    AX,ss:[BX+6]
  157.           CMP    AX,[BP+6]
  158.           JL     scan04
  159.           OR     CL,002h
  160.           CMP    AX,[BP+6]
  161.           JNE    scan04
  162.           XOR    CL,003h
  163. scan04:
  164.           CMP    CL,000h
  165.           JNE    cond01
  166.           PUSH   ss:[BX+6]
  167.           PUSH   [BP+4]
  168.           PUSH   ss:[BX+2]
  169.           MOV    AH,02Ch
  170.           PUSH   AX
  171.           MOV    AX,ss:[BX+6]
  172.           INC    AX
  173.           XCHG   AX,[BP+4]
  174.           DEC    AX
  175.           MOV    ss:[BX+6],AX
  176.           OR     Byte Ptr ss:[BX+1],004h
  177.           OR     Byte Ptr [BP+1],008h
  178.           JMP    scan
  179. cond01:
  180.           CMP    CL,001h
  181.           JNE    cond02
  182.           MOV    AX,[BP+4]
  183.           DEC    AX
  184.           MOV    ss:[BX+6],AX
  185.           MOV    AH,028h
  186.           MOV    [BP+0],AX
  187.           OR     Byte Ptr ss:[BX+1],004h
  188.           JMP    scan
  189. cond02:
  190.           CMP    CL,002h
  191.           JNE    cond04
  192.           MOV    AX,[BP+4]
  193.           DEC    AX
  194.           XCHG   AX,ss:[BX+6]
  195.           PUSH   AX
  196.           MOV    AX,[BP+6]
  197.           INC    AX
  198.           PUSH   AX
  199.           PUSH   ss:[BX+2]
  200.           MOV    AH,028h
  201.           PUSH   AX
  202.           OR     Byte Ptr ss:[BX+1],004h
  203.           OR     Byte Ptr [BP+1],028h
  204.           JMP    scan
  205. cond04:
  206.           CMP    CL,004h
  207.           JNE    cond05
  208.           MOV    AX,ss:[BX+6]
  209.           INC    AX
  210.           MOV    [BP+4],AX
  211.           OR     Byte Ptr ss:[BX+1],024h
  212.           OR     Byte Ptr [BP+1],008h
  213.           JMP    scan
  214. cond05:
  215.           CMP    CL,005h
  216.           JNE    cond06
  217.           MOV    AH,020h
  218.           MOV    [BP+0],AX
  219.           ADD    SP,8
  220.           JMP    scan
  221. cond06:
  222.           CMP    CL,006h
  223.           JNE    cond08
  224.           MOV    AX,[BP+6]
  225.           INC    AX
  226.           MOV    ss:[BX+4],AX
  227.           OR     Byte Ptr ss:[BX+1],008h
  228.           OR     Byte Ptr [BP+1],024h
  229.           JMP    scan
  230. cond08:
  231.           CMP    CL,008h
  232.           JNE    cond09
  233.           MOV    AX,ss:[BX+4]
  234.           DEC    AX
  235.           XCHG   AX,[BP+6]
  236.           PUSH   AX
  237.           MOV    AX,ss:[BX+6]
  238.           INC    AX
  239.           PUSH   AX
  240.           PUSH   [BP+2]
  241.           MOV    AX,[BP+0]
  242.           OR     AH,08h
  243.           PUSH   AX
  244.           OR     Byte Ptr ss:[BX+1],02Ch
  245.           OR     Byte Ptr [BP+1],004h
  246.           JMP    scan
  247. cond09:
  248.           CMP    CL,009h
  249.           JNE    cond10
  250.           MOV    AX,ss:[BX+4]
  251.           DEC    AX
  252.           MOV    [BP+6],AX
  253.           OR     Byte Ptr ss:[BX+1],028h
  254.           OR     Byte Ptr [BP+1],004h
  255.           JMP    scan
  256. cond10:
  257.           CMP    CL,00Ah
  258.           JNE    conderr
  259.           PUSH   [BP+6]
  260.           PUSH   ss:[BX+4]
  261.           PUSH   [BP+2]
  262.           MOV    AH,02Ch
  263.           PUSH   AX
  264.           MOV    AX,[BP+6]
  265.           INC    AX
  266.           XCHG   AX,ss:[BX+4]
  267.           DEC    AX
  268.           MOV    [BP+6],AX
  269.           OR     Byte Ptr ss:[BX+1],008h
  270.           OR     Byte Ptr [BP+1],004h
  271.           JMP    scan
  272. conderr:
  273.           MOV    AX,3
  274.           INT    10h
  275.           mov    bp,si
  276.           jmp    done
  277. scan09:
  278.           mov    bp,si                 ; Restore BP pointer from SI save area
  279.  
  280.           POP    AX                    ; Load options (AH) & bit mask (AL)
  281.           POP    DI                    ; Load vertical Y corrdinate
  282.           POP    CX                    ; Load horizontal X corrdinate
  283.  
  284.           MOV    [bp+tmpw1],CX         ; Save horizontal X corrdinate
  285.           MOV    [bp+tmpw7],CX         ;   ...
  286.           MOV    [bp+tmpw2],DI         ; Save vertical Y corrdinate
  287.  
  288.           MOV    BX,CX                 ; Copy X corrdinate
  289.           MOV    SI,CX                 ; Copy X corrdinate
  290.           MOV    AL,80h                ; Determine the starting bit to plot
  291.           AND    CL,7                  ;   ...
  292.           ROR    AL,CL                 ;   ...
  293.  
  294.           SHR    SI,1                  ; Divide X corrdinate by three and
  295.           SHR    SI,1                  ;   ...
  296.           SHR    SI,1                  ;   ...
  297.           shl    di,1
  298.           shl    di,1
  299.           add    di,[bp+tmpw2]
  300.           shl    di,1
  301.           shl    di,1
  302.           shl    di,1
  303.           shl    di,1
  304.           ADD    SI,di                 ; Load Y (row) offset in graphic memory
  305.  
  306.           MOV    [bp+tmpw3],AX         ; Save horizontal X in (AL/SI) form
  307.           MOV    [bp+tmpw4],SI         ;   ...
  308.  
  309. ;      Determine the left most bit of the current horizontal line (AL/SI).  BX
  310. ;  is the current X corrdinate.
  311.  
  312.           TEST   [bp+tmpw3],00800h     ;
  313.           JNZ    left03                ;
  314.  
  315.           TEST   AL,ES:[SI]            ; Is the current point a border?
  316.           JNZ    left03                ;   Yes, don't need to scan left
  317.  
  318.           MOV    CX,[bp+tmpw1]         ;
  319.           SUB    CX,_GDVW_X1           ; Compute Delta of X and X(left limit)
  320.           JZ     left03                ;   Zero delta, don't need to scan left
  321. left01:
  322.           ROL    AL,1                  ; Position to the next bit on the left
  323.           SBB    SI,0                  ; Automatic SI decrement on carry
  324.           TEST   AL,ES:[SI]            ; Are we now at the paint border?
  325.           LOOPZ  left01                ; No, continue scanning to the left
  326.           JZ     left02
  327.  
  328.           ROR    AL,1
  329.           ADC    SI,0
  330.           INC    CX
  331. left02:
  332.           ADD    CX,_GDVW_X1           ;
  333.           MOV    [bp+tmpw1],CX         ; Save horizontal X corrdinate
  334.           XCHG   AX,[bp+tmpw3]         ; Exchange horizontal X in (AL/SI) form
  335.           XCHG   SI,[bp+tmpw4]         ;   ...
  336. left03:
  337.  
  338. ;      Force scan to the right define by lenght value, during the force fill
  339. ;  skip over border areas
  340.  
  341.           POP    CX                    ; Load end of force area
  342.           MOV    [bp+tmpw8],CX
  343.           SUB    CX,BX                 ; Determine delta of the start and stop
  344.           INC    CX                    ;   X corrdinates
  345. force01:
  346.           TEST   AL,ES:[SI]            ; Are we at the paint border?
  347.           JNZ    force02               ;   Yes, enter force scan mode
  348.           ROR    AL,1                  ; Next bit to the right
  349.           JC     force1B
  350. force1A:
  351.           INC    BX                    ; Increment working X corrdinate
  352.           LOOP   force01               ; Continue filling to the right
  353.           JMP    short right01         ;
  354. force1B:
  355.           INC    SI                    ; Automatic SI increment on carry
  356.           CMP    CX,9
  357.           JLE    force1A
  358.           CMP    BYTE PTR ES:[SI],0
  359.           JNE    force1A
  360.           SUB    CX,8
  361.           ADD    BX,8
  362.           JMP    short force1B
  363. force02:
  364.           CALL   entry
  365.           DEC    CX
  366.           JZ     force04
  367. force03:
  368.           ROR    AL,1                  ; Next bit to the right
  369.           ADC    SI,0                  ;   Jump on overflow
  370.           INC    BX                    ;
  371.           TEST   AL,ES:[SI]            ; Are we at a non paint border?
  372.           LOOPNZ force03               ;   Yes, enter fill mode
  373.           OR     CX,CX                 ;
  374.           JNZ    force05               ;
  375. force04:
  376.           JMP    loop
  377. force05:
  378.           MOV    [bp+tmpw1],BX
  379.           MOV    [bp+tmpw3],AX
  380.           MOV    [bp+tmpw4],SI
  381.           JMP    short force01
  382.  
  383. right01:
  384.           TEST   [bp+tmpw3],00400h     ;
  385.           JNZ    right03               ;
  386.  
  387.           MOV    CX,_GDVW_X2
  388.           SUB    CX,BX                 ; Compute Delta of X and X(left limit)
  389.           JS     right03
  390.           INC    CX
  391. right02:
  392.           TEST   AL,ES:[SI]            ; Are we at the paint border?
  393.           JNZ    right03               ;   Yes, continue
  394.           ROR    AL,1                  ; Position to the next bit on the left
  395.           ADC    SI,0                  ;
  396.           INC    BX                    ; Add one to current X corrdinate
  397.           LOOP   right02               ; Continue filling to the left
  398. right03:
  399.           CALL   entry
  400.           JMP    loop
  401.  
  402. entry:
  403.           CMP    BX,[bp+tmpw1]
  404.           JNZ    entry01
  405.           RET
  406. entry01:
  407.           PUSH   BX
  408.           PUSH   AX
  409.           PUSH   SI
  410.           PUSH   CX
  411.  
  412.           MOV    CX,BX
  413.           SUB    CX,[bp+tmpw1]
  414. ;         DEC    CX
  415.  
  416.           MOV    BX,[bp+tmpw1]
  417.           AND    BX,7
  418.           SHL    BX,1
  419.           SHL    BX,1
  420.           SHL    BX,1
  421.           MOV    DI,[bp+tmpw2]
  422.           AND    DI,7
  423.           OR     BX,DI
  424.           ADD    DI,_GDGSADR
  425.           MOV    AX,[bp+tmpw3]
  426.           MOV    SI,[bp+tmpw4]
  427.  
  428.           CMP    _GDS_FLG,0
  429.           JNE    fill01
  430.  
  431. fill001:
  432.           out    DX,AL
  433.           mov    ah,es:[si]
  434.           mov    ah,_GDCOLOR
  435.           mov    es:[si],ah
  436.           ror    al,1
  437.           jnc    fill003
  438. fill002:
  439.           INC    SI
  440.           CMP    CX,8
  441.           JLE    fill003
  442.           MOV    AL,0FFh
  443.           OUT    DX,AL
  444.           MOV    ES:[SI],AH
  445.           SUB    CX,8
  446.           MOV    AL,080h
  447.           JMP    short fill002
  448. fill003:
  449.           LOOP   fill001
  450.           jmp    short fill04
  451.  
  452. ;******
  453.  
  454. fill01:
  455.           OUT    DX,AL                 ; Set graphic bit for current byte
  456.           MOV    AH,ES:[SI]            ;
  457.           push   bx
  458.           mov    bh,bl
  459.           shr    bl,1
  460.           shr    bl,1
  461.           shr    bl,1
  462.           and    bl,7
  463.           shl    bh,1
  464.           shl    bh,1
  465.           shl    bh,1
  466.           and    bh,038h
  467.           or     bl,bh
  468.           xor    bh,bh
  469.           add    bx,offset DGROUP:_GDSHAD1
  470.           inc    bx
  471.           inc    bx
  472.           MOV    AH,ds:[BX]            ;
  473.           pop    bx
  474.           MOV    ES:[SI],AH            ;
  475.           ADD    BX,8                  ;
  476.           AND    BX,63                 ;
  477.           ROR    AL,1                  ; Next bit to the right
  478.           JNC    fill03
  479. fill02:
  480.           INC    SI
  481.           CMP    CX,8
  482.           JLE    fill03
  483.           TEST   _GDMERGE,0FFh         ; Using merge mode other than zero?
  484.           JNZ    fill03                ;** Yes, skip fast paint fill logic
  485.           PUSH   AX
  486.           MOV    AL,0FFh
  487.           OUT    DX,AL
  488.           dec    dx
  489.           MOV    AX,0105h
  490.           out    dx,ax
  491.           inc    dx
  492.           MOV    AL,ES:[DI]
  493. fill02A:
  494.           CMP    CX,8
  495.           JLE    fill02B
  496.           MOV    ES:[SI],AL
  497.           INC    SI
  498.           SUB    CX,8
  499.           JMP    short fill02A
  500. fill02B:
  501.           dec    dx
  502.           MOV    AX,0A05h
  503.           out    dx,ax
  504.           MOV    AX,0FF08h
  505.           out    dx,ax
  506.           inc    dx
  507.           POP    AX
  508. fill03:
  509.           LOOP   fill01
  510.  
  511. fill04:
  512.           POP    CX
  513.           POP    SI
  514.           POP    AX
  515.           POP    BX
  516.  
  517.           TEST   [bp+tmpw3],02000h
  518.           JZ     skip01
  519.           RET
  520. skip01:
  521.           MOV    [bp+tmpw5],AX         ; Save AX in non-stack area
  522.           POP    [bp+tmpw6]
  523. top:
  524.           MOV    AX,[bp+tmpw2]
  525.           CMP    AX,_GDVW_Y1           ; Are we already at the top?
  526.           JE     bot                   ;   Yes, stack the bottow
  527.           TEST   [bp+tmpw3],08000h     ; Do we perform a force scan check?
  528.           JNZ    top01                 ;   Yes, continue
  529.  
  530.           MOV    AX,BX
  531.           DEC    AX
  532.           PUSH   AX
  533.           PUSH   [bp+tmpw1]
  534.           MOV    AX,[bp+tmpw2]
  535.           DEC    AX
  536.           PUSH   AX
  537.           MOV    AH,040h
  538.           PUSH   AX
  539.           JMP    short bot
  540. top01:
  541.  
  542.           MOV    AX,[bp+tmpw1]
  543.           CMP    AX,[bp+tmpw7]
  544.           JGE    top02
  545.  
  546. ;      store the front half
  547.  
  548.           MOV    AX,[bp+tmpw7]
  549.           DEC    AX
  550.           PUSH   AX
  551.           PUSH   [bp+tmpw1]
  552.           MOV    AX,[bp+tmpw2]
  553.           DEC    AX
  554.           PUSH   AX
  555.           MOV    AH,040h
  556.           PUSH   AX
  557. top02:
  558.           MOV    AX,BX
  559.           DEC    AX
  560.           CMP    AX,[bp+tmpw8]
  561.           JLE    bot
  562.  
  563. ;      store the back half
  564.  
  565.           PUSH   AX
  566.  
  567.           MOV    AX,[bp+tmpw8]
  568.           INC    AX
  569.           PUSH   AX
  570.           MOV    AX,[bp+tmpw2]
  571.           DEC    AX
  572.           PUSH   AX
  573.           MOV    AH,040h
  574.           PUSH   AX
  575. bot:
  576.           MOV    AX,[bp+tmpw2]
  577.           CMP    AX,_GDVW_Y2           ; Are we already at the bottow?
  578.           JNE    bot0                  ;   Yes, return         w
  579.           PUSH   [bp+tmpw6]
  580.           MOV    AX,[bp+tmpw5]         ; Restore AX from non-stack area
  581.           RET
  582. bot0:
  583.           TEST   [bp+tmpw3],04000h     ; Do we perform a force scan check?
  584.           JNZ    bot01                 ;   Yes, continue
  585.  
  586.           MOV    AX,BX
  587.           DEC    AX
  588.           PUSH   AX
  589.           PUSH   [bp+tmpw1]
  590.           MOV    AX,[bp+tmpw2]
  591.           INC    AX
  592.           PUSH   AX
  593.           MOV    AH,080h
  594.           PUSH   AX
  595.           JMP    short bot03
  596. bot01:
  597.           MOV    AX,[bp+tmpw1]
  598.           CMP    AX,[bp+tmpw7]
  599.           JGE    bot02
  600.  
  601. ;      store the front half
  602.  
  603.           MOV    AX,[bp+tmpw7]
  604.           DEC    AX
  605.           PUSH   AX
  606.           PUSH   [bp+tmpw1]
  607.           MOV    AX,[bp+tmpw2]
  608.           INC    AX
  609.           PUSH   AX
  610.           MOV    AH,080h
  611.           PUSH   AX
  612. bot02:
  613.           MOV    AX,BX
  614.           DEC    AX
  615.           CMP    AX,[bp+tmpw8]
  616.           JLE    bot03
  617.  
  618. ;      store the back half
  619.  
  620.           PUSH   AX
  621.           MOV    AX,[bp+tmpw8]
  622.           INC    AX
  623.           PUSH   AX
  624.           MOV    AX,[bp+tmpw2]
  625.           INC    AX
  626.           PUSH   AX
  627.           MOV    AH,080h
  628.           PUSH   AX
  629. bot03:
  630.           PUSH   [bp+tmpw6]
  631.           MOV    AX,[bp+tmpw5]         ; Restore AX from non-stack area
  632.           RET
  633.  
  634. done:
  635.           mov    dx,03CEh
  636.           mov    ax,3
  637.           out    dx,ax
  638.           mov    ax,5
  639.           out    dx,ax
  640.           mov    ax,0FF08h
  641.           out    dx,ax
  642.  
  643.           pop    di
  644.           pop    si
  645.           mov    sp,bp
  646.           pop    bp
  647.           ret
  648.  
  649. _gpflood  endp
  650. _text     ends
  651.           end
  652.